<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise语法糖_async&await</title>
</head>
<body>
    <script>
        
        /* 1.fetch写法 */
        /* fetch('./test.txt')
        .then(function(response){
            return response.text();
        })
        .then(function(data){
            document.write(data);
        }) */

        /* 2.语法糖写法 */
        /* async function foo(){
            let response = await fetch("./test.txt");
            let data = await response.text();  
            document.write(data);
        }
        foo(); */

        /* 3.假设foo是配置好的方法，若要其他地方函数使用 */
        async function foo(){
            var response = await fetch("./test.txt");
            var data = await response.text();
            return data
        }

        async function render(){
            var res = await foo();
            console.log(res);   // 值以拿到，但因为不设置语法糖，直接打印promise对象
        }
        render();
        

    </script>
</body>
</html>